<?php include load_template('_subnav.php')?>
<h1>Page Management</h1>

<p><?php echo link_to('Add New Page',array('controller'=>'admin/pages')); ?></p>

<div id='add_new'>
    <table border="0" cellspacing="2" cellpadding="2" width='100%'>
        <tr>
            <td><?php echo  form_tag('index') ?>              
            Choose Page: <?php echo  select_tag('pages[id]', $pages_as_options) ?>
            <?php echo submit_tag('Edit')?>
            <?php echo  end_form_tag() ?></td>
            <td><?php echo  form_tag('index') ?>
            <?php echo  hidden_field_tag('action','find_by_title') ?>            
            Search By Page Title: <?php echo  text_field_tag('title',null,array('id'=>'title','size'=>40)) ?>            
            <div class="auto_complete" id="auto_complete"></div>
            <?php echo submit_tag('Edit')?>
            <script type="text/javascript">new Ajax.Autocompleter('title', 'auto_complete', '<?php echo  url_for('search_pages') ?>', {})</script>
            <?php echo  end_form_tag() ?></td>
        </tr>
    </table>
</div>

<?php echo error_messages_for('pages')?>

<h2><?php if(!empty($page)) echo "Managing Page: <span style='color:red'>{$page['title']}</span> [".
            link_to('view', 
                    array('controller'=>'content' ,'action'=>$page['index_name']),
                    array('target'=>'_blank'))."]" ?></h2>

<?php if( !empty($page) ) { ?>
<p><b>The URL to this page is: </b>
<?php echo link_to("http://".$_SERVER['HTTP_HOST'].'/content/'.$page['index_name'],
                   "http://".$_SERVER['HTTP_HOST'].'/content/'.$page['index_name']) ?></p>
<?php } ?>

<?php
    if ( empty($page) )
    {
?>
<div id="tabPanel1" class='tab-pane'>    
        <div id="tabPage1" class='tab-page'>
        <h2 class='tab'>Add Page</h2>      
        <?php echo form_tag('index',array('validation'=>true))?>
        <?php echo hidden_field_tag('action','add_page')?>
        <?php include load_template('_form.php')?>
        <?php echo submit_tag('Add Page')?>
        <?php echo end_form_tag()?>
    </div>
</div>
<?php } else { ?>
  <div id="tabPanel" class='tab-pane'>          
      <div id="tabPage2" class='tab-page'>
          <h2 class='tab'>Page Content</h2>
           <iframe 
                  frameborder="0" 
                  id="page_preview" 
                  scrolling="auto" 
                  src="<?php echo url_for(array('controller'=>'admin/pages' ,'action'=>'show_editable_regions?id='.$page['id']))?>"
                  width="99%" 
                  height="500" style='border:1px solid #000'></iframe>
      </div>
      
    <div id="tabPage1" class='tab-page'>
        <h2 class='tab'>Page Details</h2>
        <?php echo form_tag('index',array('validation'=>true))?>
        <?php echo hidden_field_tag('action','edit_page')?>
        <?php include load_template('_form.php')?>
        <?php echo hidden_field('pages','id')?>
        <br/><?php echo submit_tag('Save Page')?>
        <?php echo end_form_tag()?>
        
        <?php if (has_access_to('Pages::Delete Pages')) {?>
            <div class='div-delete'>
            <?php echo  form_tag('delete') ?>
            <?php echo  hidden_field_tag('id',$page['id']) ?>
            <?php echo  hidden_field_tag('action','delete') ?>
            <span style='font-weight:bold'>Delete This Page?</span>
            <?php echo  submit_tag('Delete Page',array('confirm'=>'Are you sure you want to delete this page?','class'=>'submit_delete')) ?>
            <?php echo  end_form_tag() ?>
            </div>
        <?php } ?>
    </div>

    
    <div id="tabPage3" class='tab-page'>
        <h2 class='tab'>Meta Information</h2>
           <?php echo form_remote_tag(array('controller'=>'admin/pages' ,'action'=>'edit_meta'),
                    array(
                        'update'=>'success_messages',
                        'complete'=>"toggle_success();",
                        )
                        )
             ?>
            <?php echo  hidden_field('pages','id') ?>
            <?php echo  hidden_field_tag('action','edit_meta') ?>
            <label for='pages_keywords'>Page Title</label>
            <span class='hint_text'>Any value here will replace the main title of the page.</span><br />
            <?php echo  text_field('pages','meta_title',array('size'=>'30')) ?> 
            
            <label for='pages_keywords'>Meta Keywords</label>
            <?php echo  text_area('pages','meta_keywords',array('size'=>'30x5')) ?>

            <label for='pages_keywords'>Meta Description</label>
            <?php echo  text_area('pages','meta_description',array('size'=>'30x5')) ?>   
                     
            <br><br><?php echo  submit_tag('Edit Meta Content') ?>
            <?php echo  end_form_tag() ?>
   </div>
   <?php if ( has_access_to("Pages::Lock Pages")) { ?>
   <div id='tabPage4' class='tab-page'>
        <h2 class='tab'>Page Permissions</h2>
        <div style='width:550px;'>
        <p>By default anyone who has access to the Pages controller can edit pages. You can restrict access to this page by choosing the people you want to be able to access this page. By default an admin is able to edit any page.</p>
        <?php echo form_remote_tag('permissions',
                    array(
                        'name'=>'user_permissions',
                        'update'=>'success_messages',
                        'before'=>"selectAll('users[]')",
                        'complete'=>"toggle_success();",
                        )
                    )
         ?>
        <?php echo  hidden_field('pages','id') ?>
        <?php echo select_transfer('users[]', array_diff($all_users,$page_users), $page_users)?>  
        <p><?php echo submit_tag('Modify Permissions')?></p>
        <?php echo end_form_tag()?>
    </div>
   </div>
   <?php } ?>
       

</div>
<?php } ?>

    <script type="text/javascript">
        setupAllTabs();
    </script>

<?php if($has_no_index) { ?>
<div class='section'>
    <p><b>NOTE:</b> You don't currently have a page set as your index (home) page. This might be intended if you have an index.html file in your public directory.
        <?php if(file_exists(PUBLIC_HTML.'/index.html') || file_exists(PUBLIC_HTML.'/index.htm')) { echo '<b>(You Do)</b>'; } else { echo '<b>(You Don\'t)</b>'; } ?>
         But if you don't the system will try to render the home page you set here as your home page.
</div>
<?php } ?>
